#define _CRT_SECURE_NO_WARNINGS 1

#include"stack.h"

void STInit(ST* pst)
{
	assert(pst);
	pst->a = NULL;
	pst->size = 0;
	pst->capacity = 0;
}

void STDestroy(ST* pst)
{
	assert(pst);
	free(pst->a);
	pst->a = NULL;
	pst->size = 0;
	pst->capacity = 0;
}


void STPush(ST* pst, STDateType x)
{
	if (pst->size == pst->capacity)
	{
		int sz = pst->capacity == 0 ? 4 : pst->capacity *2;
		STDateType* new = (STDateType*)realloc( pst->a ,sz*sizeof(STDateType));
		assert(new);
		pst->a = new;
		pst->capacity = sz;
	}
	
	pst->a[pst->size] = x;
	pst->size++;
}

bool Empty(ST* pst)
{
	assert(pst);
	return pst->size == 0;
}

void STPop(ST* pst)
{
	assert(pst);
	assert(!Empty(pst));
	pst->size--;
}

STDateType STTop(ST* pst)
{
	assert(pst);
	assert(!Empty(pst));
	return pst->a[pst->size - 1];
}

int STSize(ST* pst)
{
	assert(pst);
	return pst->size;
}


